// 539. 最小时间差
/**
 * @param {string[]} timePoints
 * @return {number}
 */
// 最小时间差必然出现在timePoints 的两个相邻时间或者timePoints的两个首尾间
// 排序
var findMinDifference = function (timePoints) {
    const len = timePoints.length
    if (len > 1440) return 0
    timePoints.sort()
    let ans = Number.MAX_VALUE
    let t0Minutes = getMinutes(timePoints[0])
    let preMinutes = t0Minutes
    for (let i = 1; i < len; i++) {
        const minutes = getMinutes(timePoints[i])
        ans = Math.min(ans, minutes - preMinutes) //相邻时间差
        preMinutes = minutes
    }
    // 24 * 60 = 1440
    ans = Math.min(ans, t0Minutes + 1440 - preMinutes)
    return ans
};

// 鸽巢原理
// 如果timePoints的长度超过1440 那么一定有两个是相同的时间，此时可以直接返回为0
var findMinDifference = function (timePoints) {

}
const getMinutes = (t) => {
    return ((t[0].charCodeAt() - '0'.charCodeAt()) * 10 + (t[1].charCodeAt() - '0'.charCodeAt())) * 60 + (t[3].charCodeAt() - '0'.charCodeAt()) * 10 + (t[4].charCodeAt() - '0'.charCodeAt());
}


findMinDifference(["05:31", "22:08", "00:35"])